<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <title>Router</title>
    <link rel="stylesheet" type="text/css" href="css/main.css?t=000000">

    <script type="text/javascript" src="js/json2.js"></script>
    <script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
    <script type="text/javascript" src="js/jquery.form.js"></script>
    <script type="text/javascript" src="js/jquery.validate.js"></script>
    <script type="text/javascript" src="js/underscore-min.js"></script>
    <script type="text/javascript" src="js/language_list.js?t=000000"></script>
    <script type="text/javascript" src="js/language.js?t=000000"></script>
    <script type="text/javascript" src="js/language/en.js?t=000000"></script>
    <script type="text/javascript" src="js/helper.js?t=000000"></script>
    <script type="text/javascript" src="js/main.js?t=000000"></script>


    <script type="text/javascript">
        $(document).ready(function () {

            var loading = '-';



            Page.postJSON({
                json: {
                    cmd: RequestCmd.GET_LOGIN_INFO
                },
                success: function (datas) {
                    var datas = datas.data,
                        language = datas.language;
                    Page.languageList = ConvertUtil.parseHex(FormatUtil.formatValue('6') || "3E");
                    Page.language = language.web_language.toUpperCase();
                    $("script[src^='js/language/']").remove();
                    $("script[src^='js/main']").remove();
                    $.getScript('js/language/' + language.web_language.toLowerCase() + '.js', function () {
                        $.getScript('js/main.js', init);
                    });

                    function init() {
                        Page.render('#login_container', '#login_template', DOC);
                        Page.initPage(true);
                        $(window).resize(function () {
                            Page.initPage(true);
                        });

                        var $languageSelect = $('#languageSelect');
                        $languageSelect.html(Page.getLanguageList(Page.language)).change(function () {
                            Page.changeLanguage($languageSelect);
                        });

                        // 语言显隐
                        Page.isShowLangu = language.web_language_select_enable;
                        if (language.web_language_select_enable == "1") {
                            $("#languageSelect").show();
                            $(".tr_language").show();
                        } else {
                            $("#languageSelect").hide();
                            $(".tr_language").hide();
                        }

                        // 顶部状态栏内容
                        var sysStatus = datas.sys_status;
                        var wifiStatus = sysStatus.wifi;
                        var interStatus = sysStatus.ethInter;
                        $('#wifiInfo').html(StatusUtil.formatWiFiInfo(wifiStatus.status));
                        $('#wifiInfo5g').html(StatusUtil.format5gWiFiInfo(wifiStatus.status5));
                        $('#simInfo').html(StatusUtil.formatSimInfo(sysStatus.is_sim_exist));
                        for (var i = 0; i < interStatus.length; i++) {
                            if (i < 3) {
                                var j = i + 1;
                                $('#lan' + j).html(StatusUtil.formatNetInterfaceInfo(interStatus[i], "Lan" + j));
                                if (interStatus[i] == "0") {
                                    $('#lan' + j).hide(0);
                                }
                            } else if (i == 3) {
                                $('#wan1').html(StatusUtil.formatNetInterfaceInfo(interStatus[3], "Lan4/Wan"));
                                if (interStatus[3] == "0") {
                                    $('#wan1').hide(0);
                                }
                            }
                        }
                        sessionStorage["2g_register_status"] = sysStatus["2g_register_status"];
                        sessionStorage["3g_register_status"] = sysStatus["3g_register_status"];
                        sessionStorage["4g_register_status"] = sysStatus["4g_register_status"];
                        sessionStorage["rsrp"] = sysStatus.rsrp;
                        sessionStorage["signal_lvl"] = sysStatus.signal_lvl;
                        sessionStorage["wifi_status"] = wifiStatus.status;
                        sessionStorage["wifi5_status"] = wifiStatus.status5;
                        sessionStorage["network_link_stauts"] = sysStatus.network_link_stauts;
                        if (sysStatus.card_status == 0) {
                            var singalLevel = sysStatus.signal_lvl;
                            var netInfo = StatusUtil.formatSingalLevel(singalLevel);
                            $('#netInfo').html(netInfo);
                        } else {
                            var netInfo = StatusUtil.formatSingalLevel(0);
                            $('#netInfo').html(netInfo);
                        }
                        if (datas.sim_card_status == '1') {
                            $("#simPInPosition").text(DOC.title.simPInPosition);
                        }

                        // 主体右侧内容
                        var main_info = datas.main_info
                        names_device = [],
                            values_device = [],
                            names_network = [],
                            values_network = [],
                            names_modem = [],
                            values_modem = [],
                            netState = getNetState(main_info.modem_act);

                        names_device.push(DOC.device.model);
                        names_device.push(DOC.device.softwarVersion);
                        names_device.push(DOC.device.configVersion);
                        names_device.push(DOC.device.imei);
                        names_device.push(DOC.device.sn);

                        values_device.push(main_info.version_type || loading);
                        values_device.push(main_info.software_version || loading);
                        values_device.push(main_info.config_version || loading);
                        values_device.push(main_info.factory_imei || loading);
                        var sn = loading;
                        if (!!main_info.device_sn) {
                            sn = main_info.device_sn
                        }
                        else if (main_info.version_type && main_info.factory_imei) {
                            sn = main_info.version_type + main_info.factory_imei
                        }
                        values_device.push(sn);

                        if (!!main_info.wan_ipaddr) {
                            names_network.push(DOC.lbl.connectionNetworkStatus);
                            names_network.push(DOC.lbl.netMode);
                            names_network.push(DOC.net.wanIp);
                            names_network.push(DOC.net.mask);
                            names_network.push(DOC.net.gateway);
                            names_network.push(DOC.net.dns1);
                            names_network.push(DOC.net.dns2);

                            values_network.push(DOC.net.ok);
                            values_network.push(DOC.net.wiredMode);
                            values_network.push(main_info.wan_ipaddr || loading);
                            values_network.push(main_info.wan_netmask || loading);
                            values_network.push(main_info.wan_gateway || loading);
                            values_network.push(main_info.wan_first_dns || loading);
                            values_network.push(main_info.wan_second_dns || loading);
                        }

                        if (!!main_info.fourg_ipaddr && !main_info.wan_ipaddr) {
                            names_network.push(DOC.lbl.connectionNetworkStatus);
                            names_network.push(DOC.lbl.netMode);
                            names_network.push(DOC.net.wanIp);
                            names_network.push(DOC.net.mask);
                            names_network.push(DOC.net.gateway);
                            names_network.push(DOC.net.dns1);
                            names_network.push(DOC.net.dns2);

                            values_network.push(DOC.net.ok);
                            values_network.push(netState);
                            values_network.push(main_info.fourg_ipaddr || loading);
                            values_network.push(main_info.fourg_netmask || loading);
                            values_network.push(main_info.fourg_gateway || loading);
                            values_network.push(main_info.fourg_dns1 || loading);
                            values_network.push(main_info.fourg_dns2 || loading);
                        }

                        if (!main_info.wan_ipaddr && !main_info.fourg_ipaddr) {
                            names_network.push(DOC.lbl.connectionNetworkStatus);
                            names_network.push(DOC.lbl.netMode);
                            names_network.push(DOC.net.wanIp);
                            names_network.push(DOC.net.mask);
                            names_network.push(DOC.net.gateway);
                            names_network.push(DOC.net.dns1);
                            names_network.push(DOC.net.dns2);

                            values_network.push(DOC.net.fail);
                            values_network.push(DOC.net.noNetwork);
                            values_network.push(loading);
                            values_network.push(loading);
                            values_network.push(loading);
                            values_network.push(loading);
                            values_network.push(loading);
                        }

                        names_modem.push(DOC.lte.rsrp);
                        names_modem.push(DOC.lte.rssi);
                        names_modem.push(DOC.lte.rsrq);
                        names_modem.push(DOC.lte.sinr);

                        values_modem.push(main_info.modem_rsrp ? FormatUtil.formatField(main_info.modem_rsrp, 'dBm') : loading);
                        values_modem.push(main_info.modem_rssi ? FormatUtil.formatField(main_info.modem_rssi, 'dBm') : loading);
                        values_modem.push(main_info.modem_rsrq ? FormatUtil.formatField(main_info.modem_rsrq, 'dB') : loading);
                        values_modem.push(main_info.modem_sinr ? FormatUtil.formatField(main_info.modem_sinr, 'dB') : loading);

                        Page.isNULLToSpace = true;

                        var device_info_html = Page.createTable(DOC.title.deviceInfo, names_device, values_device, names_device.length, 1).replace("<td>", "<td style=\"width=100px\">");
                        $('#device_info').html(device_info_html);
                        Page.setStripeTable();
                        Page.isNULLToSpace = false;

                        var internet_checking_html = Page.createTable(DOC.title.internetChecking, names_network, values_network, names_network.length, 1).replace("<td>", "<td style=\"width=100px\">");
                        $('#internet_checking').html(internet_checking_html);

                        changeConnectionNetworkStatusValueColor(main_info.wan_ipaddr, main_info.fourg_ipaddr)

                        var net_html = Page.createTable(DOC.title.fourGInfo, names_modem, values_modem, names_modem.length, 1).replace("<td>", "<td>");
                        $('#four_G_info').html(net_html);

                        Page.setStripeTable();
                        Page.isNULLToSpace = false;

                        function getNetState(flag) {
                            var state = "-";
                            if (flag == "-1") {
                                state = "?";
                            } else if (flag == "0") {
                                state = "2g";
                            } else if (flag == "2") {
                                state = "3g";
                            } else if (flag == "7") {
                                state = "4g";
                            }
                            return state;
                        }

                        function changeConnectionNetworkStatusValueColor(wan_ipaddr, fourg_ipaddr) {
                            if (!!wan_ipaddr || !!fourg_ipaddr) {
                                $('.login_right #internet_checking table tr:first-child td').css("color", "green");
                            }
                            if (!wan_ipaddr && !fourg_ipaddr) {
                                $('.login_right #internet_checking table tr:first-child td').css("color", "red");
                            }
                        }

                        // 登录点击
                        var $username = $('#username').focus(),
                            $passwd = $('#passwd'),
                            $btnLogin = $('#btnLogin');
                        var MaxFailNum = 2;
                        sessionStorage['loginFail'] = sessionStorage['loginFail'] ? sessionStorage['loginFail'] : 0;
                        sessionStorage['failTime'] = sessionStorage['loginFail'] ? sessionStorage['loginFail'] : "";

                        $username.keydown(function (e) {
                            if (e.which == 13) {
                                $passwd.focus();
                            }
                        });

                        $passwd.keydown(function (e) {
                            if (e.which == 13) {
                                if (!$btnLogin.attr("disabled")) {
                                    $btnLogin.click();
                                }
                            }
                        });

                        function getSessionId() {
                            return Md5.md5(Math.random().toString());
                        }

                        $btnLogin.click(function () {
                            var timestamp = (new Date()).getTime();
                            if (sessionStorage['failTime'] != "") {
                                var second = parseInt((timestamp - parseInt(sessionStorage['failTime'])) / 1000);
                                if (second < 60) {
                                    var lockMsg = PROMPT.status.lockFailTimes;
                                    AlertUtil.alertMsg(lockMsg.format(60 - second));
                                    return;
                                }
                                sessionStorage['failTime'] = "";
                            }
                            var username = $username.val(), passwd = $passwd.val();
                            if (username == "") {
                                AlertUtil.alertMsg(CHECK.required.username);
                                $username.focus();
                                return false;
                            }

                            if (passwd == "") {
                                AlertUtil.alertMsg(CHECK.required.passwd);
                                $passwd.focus();
                                return false;
                            }

                            var loginSuccess = false;
                            var sessionId = getSessionId();

                            Page.postJSON({
                                json: {
                                    cmd: RequestCmd.LOGIN,
                                    method: JSONMethod.POST,
                                    sessionId: sessionId,
                                    username: username,
                                    passwd: Md5.md5(passwd)
                                },
                                success: function (data) {
                                    loginSuccess = data.success;
                                    sessionStorage['sessionId'] = data.sessionId;
                                    sessionStorage['loginName'] = username;
                                    sessionStorage['auth'] = parseInt(data.auth, 16).toString(2);
                                    sessionStorage['level'] = data.level;
                                    sessionStorage['loginFail'] = 0;
                                    sessionStorage['failTime'] = "";
                                    sessionStorage['timeout'] = data.timeout;
                                    location.href = Page.getUrl("index.html");
                                },
                                fail: function (data) {
                                    var failMsg = PROMPT.status.loginFail;
                                    AlertUtil.alertMsg(failMsg.format(3 - parseInt(sessionStorage['loginFail'])));

                                    if (MaxFailNum >= parseInt(sessionStorage['loginFail'])) {
                                        sessionStorage['loginFail'] = parseInt(sessionStorage['loginFail']) + 1;
                                    } else {
                                        sessionStorage['failTime'] = timestamp;
                                        sessionStorage['loginFail'] = 0;
                                    }
                                }
                            });
                        });
                    }
                }
            });

            var timeout = null;
            if (timeout) {
                clearTimeout(timeout);
                timeout = null
            }
            timeout = setTimeout(StatusUtil.getSysStatus, 10000);

            function addFooterHtml() {
                var copyright = DOC.copyright;
                $('#copyright').text(copyright)
            }

            addFooterHtml();

        });

        function noImage(img) {
            img.style.display = "none";
        }


    </script>
</head>

<body style="overflow: hidden">
    <div id="header">
        <div id="logoDiv"><img src="images/customer.gif" onerror="noImage(this)"></div>
        <div id="siginfo">
            <table cellpadding="0" cellspacing="4">
                <tr>
                    <td id="simInfo"></td>
                    <td id="netInfo"></td>
                    <td id="wifiInfo"></td>
                    <td id="wifiInfo5g"></td>
                    <td id="lteUsbInfo" style="display:none;"></td>
                    <td id="lan1"></td>
                    <td id="lan2"></td>
                    <td id="lan3"></td>
                    <td id="lan4" style="display:none;"></td>
                    <td id="wan1"></td>
                    <td id="smsInfo"></td>
                </tr>
            </table>
        </div>
    </div>
    <div id="main" class="login_main">
        <div id="left" class="login_left">
            <div id="left_t" class="login_left_t"><img src=""></div>
            <div id="left_m" class="login_left_m">
                <div id="login_container">
                    <script type="text/template" id="login_template">
                        <div class="login_background_container">
                            <div class = "<%- DOC.login.backgroundImg %>">
                                <div class="login_desc">                                      
                                    <div class="login_desc_username"><%- DOC.login.username %></div>
                                    <div class="login_desc_password"><%- DOC.login.passwd %></div>
                                    <div class="login_desc_language"><%- DOC.login.language %></div>
                                </div>
                                <table class="login_table">                                                                        
                                    <tr class="tr_login tr_username">
                                        <td>                                           
                                            <input type="text" id="username" name="username" maxlength="20" />
                                        </td>
                                    </tr>
                                    <tr class="tr_login tr_password">
                                        <td>                       
                                            <input type="password" id="passwd" name="passwd" maxlength="20" />
                                        </td>
                                    </tr>
                                    <tr class="tr_login tr_language">                         
                                        <td class="td_language">
                                            <select id="languageSelect" name="languageSelect"></select>
                                        </td>  
                                    </tr> 
                                    <tr class="tr_login tr_td_btn">
                                        <td><input type="button" id="btnLogin" value="<%- btn.login %>" /></td>
                                    </tr>
                                </table>
                            </div>                  
                        </div>                         
                </script>
                </div>
            </div>
            <div id="left_b" class="login_left_b"></div>
        </div>

        <div class="login_right">
            <div id="device_info"></div>
            <div id="internet_checking"></div>
            <div id="four_G_info"></div>
        </div>
    </div>

    <p id="copyright"></p>

</body>

</html>